/*************************
申诉界面
* */
<template>
  <div>
    <el-dialog
      title="事件考核处理"
      :close-on-click-modal="true"
      :visible.sync="visible"
      top="8vh"
      width="70%"
      @close="closeDialog()"
    >
      <el-form ref="dataForm" :model="dataForm" :rules="rules" class="boxsty"  label-width="120px"><!--  @keyup.enter.native="dataFormSubmit()"  -->
        <el-form-item label="标题：" prop="sjbt">
          <span>{{dataForm.sjbt}}</span>
        </el-form-item>

        <el-form-item label="考核周期：" prop="khzq">
          <span>{{dataForm.khzq}}</span>
        </el-form-item>

        <el-form-item label="描述：" prop="sjdesc">
          <span>{{dataForm.sjdesc}}</span>
        </el-form-item>

        <el-form-item label="考核对象：">
          <el-table
            ref="multipleTable"
            :data="tableData"
            style="width: 100%;"
            tooltip-effect="dark"
          >
            <el-table-column type="index"   width="70" align="center" label="序号" ></el-table-column>

            <el-table-column
              v-if="showRY"
              prop="username"
              label="员工编号" width="120" align="center"  show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              v-if="showRY"
              prop="realname"
              label="姓名" width="120" align="center"  show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              v-if="showRY"
              prop="deptName"
              label="部门" width="120" align="center"  show-overflow-tooltip>
            </el-table-column>

            <el-table-column
              v-if="!showRY"
              prop="realname"
              label="机构名称"
              width="120" align="center"  show-overflow-tooltip>
            </el-table-column>

            <el-table-column
              prop="lbms"
              width="120" label="类别"  align="center" >
            </el-table-column>
            <el-table-column
              prop="yjms"
              width="120" label="依据"  align="center"  show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              prop="bz"
              width="120" label="标准" align="center"  show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              prop="zbgz"
              width="120" label="指标规则" align="center"  show-overflow-tooltip>
            </el-table-column>


            <el-table-column
              prop="jjx"
              header-align="center"
              width="120"
              align="center"
              label="奖金项"
              show-overflow-tooltip
            ></el-table-column>

            <el-table-column
              prop="jkjj"
              header-align="center"
              width="100"
              align="center"
              fixed="right"
              label="加扣奖金"
              show-overflow-tooltip
            ></el-table-column>

            <el-table-column
              prop="jkfz"
              fixed="right"
              label="加扣分值" align="center"  width="100" show-overflow-tooltip>
            </el-table-column>

            <el-table-column
              prop="xgjj"
              fixed="right"
              label="评审奖金" align="center"  width="100">
            </el-table-column>

            <el-table-column
              prop="xgfz"
              fixed="right"
              label="评审分值" align="center"  width="100">
            </el-table-column>



            <el-table-column
              prop="ssjj"
              fixed="right"
              label="申诉奖金" align="center"  width="100">
              <template slot-scope="scope">
                <el-input v-model="scope.row.ssjj"
                          oninput="value=value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace(/(\.\d+)\./g, '$1').replace(/^0+(\d)/, '$1').replace(/(\d{15})\d*/, '$1').replace(/(\.\d{2})\d*/, '$1')"
                          @blur="ssjjChange"
                ></el-input>
              </template>
            </el-table-column>

            <el-table-column
              prop="ssfz"
              fixed="right"
              label="申诉分值" align="center"  width="100">
              <template slot-scope="scope">
                <el-input v-model="scope.row.ssfz"
                          oninput="value=value.replace(/[^\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace(/(\.\d+)\./g, '$1').replace(/^0+(\d)/, '$1').replace(/(\d{15})\d*/, '$1').replace(/(\.\d{2})\d*/, '$1')"
                          @blur="ssfzChange"
                ></el-input>
              </template>
            </el-table-column>


            <el-table-column label="操作" width="100" fixed="right">
               <template slot-scope="scope">
                  <el-button type="danger" @click="invalid(scope.row)" v-if="showValidBtn">作废</el-button>
                  <el-button type="danger"  v-else :disabled="true">已作废</el-button>
               </template>
            </el-table-column>

          </el-table>
        </el-form-item>

        <el-form-item label="申诉理由：" prop="ssly">
          <span>{{dataForm.ssly}}</span>
        </el-form-item>

        <el-form-item label="申诉回复：" prop="sshf">
          <el-input type="textarea" :rows="4" placeholder="请输入申诉回复" v-model="dataForm.sshf" clearable></el-input>
        </el-form-item>

      </el-form>

      <span slot="footer" class="dialog-footer">
         <el-button type="success"  @click="agree"  v-loading="isSubmit">通过</el-button>
         <el-button type="danger"  @click="refuse" >不通过</el-button>
         <el-button type="primary"  @click="closeDialog">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
    import {hfSs,invalid} from "@/api/dailyExamine/eventExamine/appealHandle.js";
    export default {
        data() {
            var checkSshf = (rule, value, callback) => {
                if (value) {
                    if (value.length>250) {
                        callback("最多可输入250个字符!");
                    } else {
                        callback();
                    }
                } else {
                    callback("请输入申诉回复内容");
                }
            };
            return {
                isSubmit: false, //保存按钮的loading
                showRY:true,
               // khrNameList: [],
                visible: false,
                dataForm: {},
                tableData:[],
                rules:{
                    sshf: [{ validator:checkSshf,trigger: "blur"}]
                },
                showValidBtn:true
            };
        },
        watch: {},
        created() {},
        methods: {
            //初始化
            csh() {
                this.dataForm = {};
            },
            init(obj) {
                if (obj) {
                    this.dataForm = obj;
                    this.tableData.push(obj) ;
                   // this.khrNameList = obj.khrList;
                    this.showRY = obj.khtype=='ry'?true:false;
                    this.$nextTick(() => {
                        this.$refs.multipleTable.doLayout();
                    })
                }

                this.visible = true;
            },
            //通过
            agree(){
                this.isSubmit = true;
                this.$refs["dataForm"].validate(valid => {
                    console.log(this.tableData[0])
                    let paramsObj = {
                        sshf:this.dataForm.sshf,
                        ssfz:this.tableData[0].ssfz,
                        ssjj:this.tableData[0].ssjj,
                        id:this.tableData[0].id
                    }
                    if (valid) {
                        console.log(paramsObj)
                        if (valid) {
                            hfSs(paramsObj,2).then(r => {
                                console.log(r.data) ;
                                if (r.data.code == 0) {
                                    this.isSubmit = false;
                                    this.$emit("refreshDataList");
                                    this.closeDialog();
                                    this.$message.success("提交成功");
                                }
                            });
                        } else {
                            return false;
                        }
                    } else {
                        return false;
                    }
                });

            },
            //不通过
            refuse(){
                this.isSubmit = true;
                this.$refs["dataForm"].validate(valid => {
                    console.log(this.tableData[0])
                    let paramsObj = {
                        sshf:this.dataForm.sshf,
                        id:this.tableData[0].id,
                       // ssfz:this.tableData[0].ssfz
                    }
                    if (valid) {
                        console.log(paramsObj)
                        if (valid) {
                            hfSs(paramsObj,3).then(r => {
                                console.log(r.data) ;
                                if (r.data.code == 0) {
                                    this.isSubmit = false;
                                    this.$emit("refreshDataList");
                                    this.closeDialog();
                                    this.$message.success("提交成功");
                                }
                            });
                        } else {
                            return false;
                        }
                    } else {
                        return false;
                    }
                });




            },
            closeDialog() {
               // this.visible = false;
                this.$emit("closeAppealDialog");
            },
            handleChange:function () {

            },
            //作废
            invalid(row) {
                let paramsObj = {
                    id:this.tableData[0].id,
                    sjkhid:this.tableData[0].sjkhid
                }
                // 确定 同意
                const h = this.$createElement;
                this.$msgbox({
                    title: '提示',
                    message: h('p', {style: " font-size:16px"}, [
                        h('span', null, '对此单进行作废'),
                    ]),
                    showCancelButton: true,
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    beforeClose: (action, instance, done) => {
                        if (action === 'confirm') {
                            invalid(paramsObj,4).then(r => {
                                if (r.data.code == 0) {
                                    this.$message.success("已作废");
                                    this.showValidBtn = false ;
                                    this.closeDialog();
                                    this.$emit("refreshDataList");
                                } else {
                                    this.$message.error(r.data.msg);
                                }

                            });
                            done();
                        } else {
                            done();
                        }
                    }
                }).then(action => {
                });
            },
            ssjjChange(e){ //申诉奖金
                this.dataForm.ssjj = e.target.value
            },
            ssfzChange(e){//申诉分值
                this.dataForm.ssfz = e.target.value
            }

        }
    };
</script>
<style scoped>
  /deep/.boxsty{padding: 20px 30px!important;}
  /deep/.el-table th{padding: 5px!important;}

  .el-divider {
    background-color: #fff;
  }
  .tree-box {
    height: 500px;
    overflow: auto;
  }
</style>
